<?php
namespace app\api\controller;
use app\admin\model\Comment;
use think\Db;
class Business extends Common{
    public function _initialize()
    {
        // todo...
        parent::_initialize();
    }

    public function __construct() //Db::connect('database_app');
    {
        $this->db_app = Db::connect('database_app');
    }

    //商学院首页动态
    public function recentDynamic()
    {
        $info = Db::name('business_college_dynamic')
                  -> field('dy_id,dy_title,dy_pic,dy_des,dy_time')
                  -> where('dy_isdel','1')
                  -> where('dy_type','商学院')
                  -> where('dy_platformid','neq','')
                  -> order('dy_time desc')
                  -> limit(2)
                  -> select();
        if($info){
            $this->outData['data'] = $info;
            $this->outData['code'] = 1;
            $this->outData['message'] = "操作成功";
            return $this->outData;
        }else{
            $this->outData['code'] = 3;
            $this->outData['message'] = "暂无数据";
            return $this->outData;
        }
    }

    //动态详情  参数动态Id   dy_id  用户id  userid
    public function recentDynamicDetail()
    {
        $dy_id = input('dy_id');
        $userid = input('userid');
        Db::name('business_college_dynamic')->where('dy_id',$dy_id)->setInc('dy_liul');
        $info = Db::name('business_college_dynamic')
                     -> field("dy_id,dy_type,dy_pic,dy_title,dy_des,dy_content,dy_time,dy_liul,dy_pingl,dy_dianz,dy_dianzuserid")
                     -> where('dy_id',$dy_id)
                     -> find();
        if($info){
            //点赞状态
            $useridArr = explode(',', $info['dy_dianzuserid']);
            $result = array_search($userid, $useridArr);//返回键值
            if($result !== false){
                $info['dianzStatus'] = '已点赞';
            }else{
                $info['dianzStatus'] = '未点赞';
            }
            unset($info['dy_dianzuserid']);
            //收藏状态
            $res = Db::name('mycollection') -> where('userid',$userid) -> where('type','动态') -> where('type_id',$dy_id) -> find();
            if($res){
                //已收藏
                $info['collectionStatus'] = '已收藏';
            }else{
                //未收藏
                $info['collectionStatus'] = '未收藏';
            }
            $this->outData['data'] = $info;
            $this->outData['code'] = 1;
            $this->outData['message'] = "操作成功";
            return $this->outData;
        }else{
            $this->outData['code'] = 2;
            $this->outData['message'] = "操作失败";
            return $this->outData;
        }
        
    }

    //动态点赞,取消点赞 动态id  dy_id  用户id  userid
    public function dynamicDianzNum()
    {
        $dy_id = input('dy_id');
        $userid = input('userid');
        $info = Db::name('business_college_dynamic') -> where('dy_id',$dy_id) -> find();
        if($info['dy_dianzuserid'])
        {
            $useridArr = explode(',', $info['dy_dianzuserid']);
            $result = array_search($userid, $useridArr);//返回键值
            if($result !== false){//已点赞,取消点赞
                $res = Db::name('business_college_dynamic')->where('dy_id',$dy_id)->setDec('dy_dianz');
                unset($useridArr[$result]);
            }else{//未点赞，点赞
                $res = Db::name('business_college_dynamic')->where('dy_id',$dy_id)->setInc('dy_dianz');
                $useridArr[] = $userid;
            }
        }else{
            $res = Db::name('business_college_dynamic')->where('dy_id',$dy_id)->setInc('dy_dianz');
            $useridArr[] = $userid;
        }
        $useridString = implode($useridArr,',');
        Db::name('business_college_dynamic') -> where('dy_id',$dy_id) -> update(['dy_dianzuserid' => $useridString]);
        if($res){
            $this->outData['code'] = 1;
            $this->outData['message'] = "操作成功";
            return $this->outData;
        }else{
            $this->outData['code'] = 2;
            $this->outData['message'] = "操作失败";
            return $this->outData;
        }
    }

    //我的学习 用户信息 参数 userid
    public function userInfo()
    {
        $userid = input('userid');
        $info = $this->db_app->table('genericattribute')
                    -> alias('g')
                    -> join('yunlutong.customer c','g.EntityId = c.Id')
                    -> field('c.NickName,g.Value as headPic')
                    -> where('g.EntityId',$userid)
                    -> where('g.Key','Avatar')
                    -> select();
        if($info){
            $data = $info[0];
            $this->outData['data'] = $data;
            $this->outData['code'] = 1;
            $this->outData['message'] = "操作成功";
            return $this->outData;
        }else{
            $this->outData['code'] = 2;
            $this->outData['message'] = "操作失败";
            return $this->outData;
        }
        
    }

    //观看历史 参数 userid
    public function watchHistory()
    {
        $userid = input('userid');
        $info = Db::name('watchhistory') -> where('userid',$userid) -> where('isdel',1) -> select();
        if($info){
            $this->outData['data'] = $info;
            $this->outData['code'] = 1;
            $this->outData['message'] = "操作成功";
            return $this->outData;
        }else{
            $this->outData['code'] = 3;
            $this->outData['message'] = "暂无数据";
            return $this->outData;
        }
    }

    //观看历史删除  参数 观看历史id 多个用英文','链接
    public function delWatchHistory()
    {
        $idArr = input('id');
        $res = Db::name('watchhistory') -> where('id','in',$idArr) -> update(['isdel' => 0]);
        if($res){
            $this->outData['code'] = 1;
            $this->outData['message'] = "操作成功";
            return $this->outData;
        }else{
            $this->outData['code'] = 2;
            $this->outData['message'] = "操作失败";
            return $this->outData;
        }
    }

    //离线下载 参数 userid
    public function offlineDownload()
    {
        $userid = input('userid');
        $info = Db::name('offlinedownload') -> where('userid',$userid) -> where('isdel',1) -> select();
        if($info){
            $this->outData['data'] = $info;
            $this->outData['code'] = 1;
            $this->outData['message'] = "操作成功";
            return $this->outData;
        }else{
            $this->outData['code'] = 3;
            $this->outData['message'] = "暂无数据";
            return $this->outData;
        }
    }

    //离线下载删除  参数  下载id 多个用英文','链接
    public function delOfflineDownload()
    {
        $idArr = input('id');
        $res = Db::name('offlinedownload') -> where('id','in',$idArr) -> update(['isdel' => 0]);
        if($res){
            $this->outData['code'] = 1;
            $this->outData['message'] = "操作成功";
            return $this->outData;
        }else{
            $this->outData['code'] = 2;
            $this->outData['message'] = "操作失败";
            return $this->outData;
        }
    }

    //我的分享 参数 userid
    public function myshare($userid)
    {
        $userid = input('userid');
        $info = Db::name('myshare') -> where('userid',$userid) -> where('isdel',1) -> select();
        if($info){
            $this->outData['data'] = $info;
            $this->outData['code'] = 1;
            $this->outData['message'] = "操作成功";
            return $this->outData;
        }else{
            $this->outData['code'] = 3;
            $this->outData['message'] = "暂无数据";
            return $this->outData;
        }
    }

    //我的分享删除  参数  分享id 多个用英文','链接
    public function delMyshare()
    {
        $idArr = input('id');
        $res = Db::name('myshare') -> where('id','in',$idArr) -> update(['isdel' => 0]);
        if($res){
            $this->outData['code'] = 1;
            $this->outData['message'] = "操作成功";
            return $this->outData;
        }else{
            $this->outData['code'] = 2;
            $this->outData['message'] = "操作失败";
            return $this->outData;
        }
    }

    //我的收藏 参数 userid
    public function mycollection()
    {
        $userid = input('userid');
        $info = Db::name('mycollection') -> where('userid',$userid) -> select();
        if($info){
            $this->outData['data'] = $info;
            $this->outData['code'] = 1;
            $this->outData['message'] = "操作成功";
            return $this->outData;
        }else{
            $this->outData['code'] = 3;
            $this->outData['message'] = "暂无数据";
            return $this->outData;
        }
    }

    //我的收藏删除  参数  分享id 多个用英文','链接
    public function delMycollection()
    {
        $idArr = input('id');
        $res = Db::name('mycollection') -> where('id','in',$idArr) -> delete();
        if($res){
            $this->outData['code'] = 1;
            $this->outData['message'] = "操作成功";
            return $this->outData;
        }else{
            $this->outData['code'] = 2;
            $this->outData['message'] = "操作失败";
            return $this->outData;
        }
    }

    //观看历史添加  参数 用户id  userid  课程id  courseid  观看时间 watchtime
    public function addWatchHistory()
    {
        $course_id = input('courseid');
        $userid = input('userid');
        $watchtime = input('watchtime');
        $data = input('post.');
        $courseInfo = Db::name('business_college_course') -> where('course_id',$course_id) -> find();
        $data['title'] = $courseInfo['course_title'];
        $data['cover'] = $courseInfo['course_cover'];
        $data['time'] = date('Y-m-d H:i:s',time());
        //判断观看历史是否已经存在
        $result = Db::name('watchhistory') -> where('userid',$userid) -> where('courseid',$course_id) -> find();
        if($result){//存在 更新
            $res = Db::name('watchhistory') -> where('id',$result['id']) -> update(['watchtime' => $watchtime,'time' => $data['time']]);
        }else{//不存在，新增
            $res = Db::name('watchhistory') -> insert($data);
        }

        if($res){
            $this->outData['code'] = 1;
            $this->outData['message'] = "操作成功";
            return $this->outData;
        }else{
            $this->outData['code'] = 2;
            $this->outData['message'] = "操作失败";
            return $this->outData;
        }
    }

    //离线下载添加  参数 用户id  userid  课程id  courseid  观看时间 watchtime
    public function addOfflineDownload()
    {
        $course_id = input('courseid');
        $userid = input('userid');
        $watchtime = input('watchtime');
        $data = input('post.');
        $courseInfo = Db::name('business_college_course') -> where('course_id',$course_id) -> find();
        $data['title'] = $courseInfo['course_title'];
        $data['cover'] = $courseInfo['course_cover'];
        $data['time'] = date('Y-m-d H:i:s',time());
        //判断观看历史是否已经存在
        $result = Db::name('offlinedownload') -> where('userid',$userid) -> where('courseid',$course_id) -> find();
        if($result){//存在 更新
            $res = Db::name('offlinedownload') -> where('id',$result['id']) -> update(['watchtime' => $watchtime,'time' => $data['time']]);
        }else{//不存在，新增
            $res = Db::name('offlinedownload') -> insert($data);
        }

        if($res){
            $this->outData['code'] = 1;
            $this->outData['message'] = "操作成功";
            return $this->outData;
        }else{
            $this->outData['code'] = 2;
            $this->outData['message'] = "操作失败";
            return $this->outData;
        }
    }

    //我的收藏添加、取消 参数 用户id  userid  模块类型 type(包括动态，课程，素材)  模块id type_id
    public function addCollection()
    {
        $userid = input('userid');
        $type = input('type');
        $type_id = input('type_id');
        $data['userid'] = $userid;
        $data['type'] = $type;
        $data['type_id'] = $type_id;
        $data['time'] = date('Y-m-d H:i:s',time());
        switch ($type) {
          case '动态':
            $info = Db::name('business_college_dynamic') -> where('dy_id',$type_id) -> find();
            $data['title'] = $info['dy_title'];
            $data['cover'] = ltrim($info['dy_pic'],'.');
            break;
          case '课程':
            $info = Db::name('business_college_course') -> where('course_id',$type_id) -> find();
            $data['title'] = $info['course_title'];
            $data['cover'] = $info['course_cover'];
            break;
          case '素材':
            $info = Db::name('business_college_material') -> where('mat_id',$type_id) -> find();
            $data['title'] = $info['mat_title'];
            $data['cover'] = $info['mat_cover'];
            break;
        }
        //判断是否已收藏
        $result = Db::name('mycollection') -> where('userid',$userid) -> where('type',$type) -> where('type_id',$type_id) -> find();
        if($result){
            //已收藏 取消收藏
            $res = Db::name('mycollection') -> delete($result['id']);
        }else{
            //未收藏
            $res = Db::name('mycollection') -> insert($data);
        }
        if($res){
            $this->outData['code'] = 1;
            $this->outData['message'] = "操作成功";
            return $this->outData;
        }else{
            $this->outData['code'] = 2;
            $this->outData['message'] = "操作失败";  
            return $this->outData;
        }

    }

    //我的分享添加 参数 用户id  userid  模块类型 type(包括动态，课程，素材)  模块id type_id
    public function addShare()
    {
        $userid = input('userid');
        $type = input('type');
        $type_id = input('type_id');
        $data['userid'] = $userid;
        $data['type'] = $type;
        $data['type_id'] = $type_id;
        $data['time'] = date('Y-m-d H:i:s',time());
        switch ($type) {
          case '动态':
            $info = Db::name('business_college_dynamic') -> where('dy_id',$type_id) -> find();
            $data['title'] = $info['dy_title'];
            $data['cover'] = ltrim($info['dy_pic'],'.');
            break;
          case '课程':
            $info = Db::name('business_college_course') -> where('course_id',$type_id) -> find();
            $data['title'] = $info['course_title'];
            $data['cover'] = $info['course_cover'];
            break;
          case '素材':
            $info = Db::name('business_college_material') -> where('mat_id',$type_id) -> find();
            $data['title'] = $info['mat_title'];
            $data['cover'] = $info['mat_cover'];
            break;
        }
        //判断是否已分享
        $result = Db::name('myshare') -> where('userid',$userid) -> where('type',$type) -> where('type_id',$type_id) -> find();
        if($result){
            //已分享 啥也不做
            $res = true;
        }else{
            //未分享
            $res = Db::name('myshare') -> insert($data);
        }
        if($res){
            $this->outData['code'] = 1;
            $this->outData['message'] = "操作成功";
            return $this->outData;
        }else{
            $this->outData['code'] = 2;
            $this->outData['message'] = "操作失败";  
            return $this->outData;
        }   
    }

   //课程中心课程列表 参数 搜索内容  keyword  当前页page 每页显示条数 listRows
   public function courseList()
   {
        $page = input('page');
        $listRows = input('listRows');
        // 是否有参数传入
        if (input('?param.keyword')) {
            $keyword = input('param.keyword');
        } else {
            $keyword = '';
        }
        $info = Db::name('business_college_course')
                    ->alias('c')
                    ->join('ylt_business_college_teacher t','t.tea_id = c.course_teaid')
                    ->field('course_id,course_cover,course_title,tea_name,course_dianz,course_liul')
                    ->where('course_platformid','neq','')
                    ->where('course_isdel',1)
                    ->where('course_title|course_des','like','%'.$keyword.'%')
                    ->order('course_sort desc,course_id desc')
                    ->page($page,$listRows)
                    ->select();
        if($info)
        {
            $this->outData['data'] = $info;
            $this->outData['code'] = 1;
            $this->outData['message'] = "操作成功";
            return $this->outData;
        }else{
            $this->outData['code'] = 3;
            $this->outData['message'] = "暂无数据";
            return $this->outData;
        }
   }

   //课程详情 参数课程id   course_id  用户id  userid
   public function courseDetail()
   {
        $course_id = input('course_id');
        $userid = input('userid');
        Db::name('business_college_course')->where('course_id',$course_id)->setInc('course_liul');//浏览自增
        //点赞状态
        $info = Db::name('business_college_course')
                    ->alias('c')
                    ->join('ylt_business_college_teacher t','t.tea_id = c.course_teaid')
                    ->field('c.course_id,c.course_video,c.course_cover,c.course_title,c.course_des,c.course_dianz,c.course_liul,c.course_pingl,c.course_time,c.course_play,c.course_dianzuserid,t.tea_name')
                    ->where('course_id',$course_id)
                    ->find();
        if($info){
            $useridArr = explode(',', $info['course_dianzuserid']);
            $result = array_search($userid, $useridArr);//返回键值
            if($result !== false){
                $info['dianzStatus'] = '已点赞';
            }else{
                $info['dianzStatus'] = '未点赞';
            }
            unset($info['course_dianzuserid']);
            //收藏状态
            $res = Db::name('mycollection') -> where('userid',$userid) -> where('type','课程') -> where('type_id',$course_id) -> find();
            if($res){
                //已收藏
                $info['collectionStatus'] = '已收藏';
            }else{
                //未收藏
                $info['collectionStatus'] = '未收藏';
            }
            $this->outData['data'] = $info;
            $this->outData['code'] = 1;
            $this->outData['message'] = "操作成功";
            return $this->outData;
        }else{
            $this->outData['code'] = 2;
            $this->outData['message'] = "操作失败";
            return $this->outData;
        }
        
   }

   //课程视频播放次数 参数课程id course_id
   public function coursePlayNum()
   {
        $id = input('course_id');
        $res = Db::name('business_college_course')->where('course_id',$id)->setInc('course_play');
        if($res){
            $this->outData['code'] = 1;
            $this->outData['message'] = "操作成功";
            return $this->outData;
        }else{
            $this->outData['code'] = 2;
            $this->outData['message'] = "操作失败";
            return $this->outData;
        }
   }

   //课程点赞,取消点赞 课程id  course_id  用户id  userid
   public function courseDianzNum()
   {
        $course_id = input('course_id');
        $userid = input('userid');
        $info = Db::name('business_college_course') -> where('course_id',$course_id) -> find();
        if($info['course_dianzuserid']){
            $useridArr = explode(',', $info['course_dianzuserid']);
            $result = array_search($userid, $useridArr);//返回键值
            if($result !== false){//已点赞,取消点赞
                $res = Db::name('business_college_course')->where('course_id',$course_id)->setDec('course_dianz');
                unset($useridArr[$result]);
            }else{//未点赞，点赞
                $res = Db::name('business_college_course')->where('course_id',$course_id)->setInc('course_dianz');
                $useridArr[] = $userid;
            }
        }else{
            $res = Db::name('business_college_course')->where('course_id',$course_id)->setInc('course_dianz');
            $useridArr[] = $userid;
        }
        
        $useridString = implode(',', $useridArr);
        Db::name('business_college_course') -> where('course_id',$course_id) -> update(['course_dianzuserid' => $useridString]);
        if($res){
            $this->outData['code'] = 1;
            $this->outData['message'] = "操作成功";
            return $this->outData;
        }else{
            $this->outData['code'] = 2;
            $this->outData['message'] = "操作失败";
            return $this->outData;
        }
   }

   //课程中心资料列表 参数 搜索内容  keyword  当前页page 每页显示条数 listRows
   public function materialList()
   {
        $page = input('page');
        $listRows = input('listRows');
        // 是否有参数传入
        if (input('?param.keyword')) {
            $keyword = input('param.keyword');
        } else {
            $keyword = '';
        }
        $info = Db::name('business_college_material')
                    ->field('mat_id,mat_title,mat_cover,mat_des,mat_dianz,mat_liul')
                    ->where('mat_platformid','neq','')
                    ->where('mat_isdel',1)
                    ->where('mat_title|mat_des','like','%'.$keyword.'%')
                    ->order('mat_sort desc,mat_id desc')
                    ->page($page,$listRows)
                    ->select();
        if($info)
        {
            $this->outData['data'] = $info;
            $this->outData['code'] = 1;
            $this->outData['message'] = "操作成功";
            return $this->outData;
        }else{
            $this->outData['code'] = 3;
            $this->outData['message'] = "暂无数据";
            return $this->outData;
        }
   }
   //素材详情 素材id mat_id  用户id userid
   public function materialDetail()
   {

        $mat_id = input('mat_id');
        $userid = input('userid');
        Db::name('business_college_material')->where('mat_id',$mat_id)->setInc('mat_liul');
        $info = Db::name('business_college_material')
                    ->field('mat_id,mat_title,mat_des,mat_content,mat_original,mat_cover,mat_dianz,mat_liul,mat_pingl,mat_time,mat_dianzuserid')
                    ->where('mat_id',$mat_id)
                    ->find();
        if($info){
            $useridArr = explode(',', $info['mat_dianzuserid']);
            $result = array_search($userid, $useridArr);//返回键值
            if($result !== false){
                $info['dianzStatus'] = '已点赞';
            }else{
                $info['dianzStatus'] = '未点赞';
            }
            unset($info['mat_dianzuserid']);
            //收藏状态
            $res = Db::name('mycollection') -> where('userid',$userid) -> where('type','素材') -> where('type_id',$mat_id) -> find();
            if($res){
                //已收藏
                $info['collectionStatus'] = '已收藏';
            }else{
                //未收藏
                $info['collectionStatus'] = '未收藏';
            }
            $this->outData['data'] = $info;
            $this->outData['code'] = 1;
            $this->outData['message'] = "操作成功";
            return $this->outData;
        }else{
            $this->outData['code'] = 2;
            $this->outData['message'] = "操作失败";
            return $this->outData;
        }
   }

   //素材点赞 素材id  mat_id  用户id  userid
   public function MaterialDianzNum()
   {
        $mat_id = input('mat_id');
        $userid = input('userid');
        $info = Db::name('business_college_material') -> where('mat_id',$mat_id) -> find();
        if($info['mat_dianzuserid']){
            $useridArr = explode(',', $info['mat_dianzuserid']);
            $result = array_search($userid, $useridArr);//返回键值
            if($result !== false){//已点赞,取消点赞
                $res = Db::name('business_college_material')->where('mat_id',$mat_id)->setDec('mat_dianz');
                unset($useridArr[$result]);
            }else{//未点赞，点赞
                $res = Db::name('business_college_material')->where('mat_id',$mat_id)->setInc('mat_dianz');
                $useridArr[] = $userid;
            }
        }else{
            $res = Db::name('business_college_material')->where('mat_id',$mat_id)->setInc('mat_dianz');
            $useridArr[] = $userid;
        }
        $useridString = implode(',', $useridArr);
        Db::name('business_college_material') -> where('mat_id',$mat_id) -> update(['mat_dianzuserid' => $useridString]);
        if($res){
            $this->outData['code'] = 1;
            $this->outData['message'] = "操作成功";
            return $this->outData;
        }else{
            $this->outData['code'] = 2;
            $this->outData['message'] = "操作失败";
            return $this->outData;
        }
   }

   //热门课程
   public function hotCourse()
   {   
        $info = Db::name('business_college_course')
                    ->field('course_id,course_cover,course_title')
                    ->where('course_isdel','1')
                    ->where('course_ishot','1')
                    ->where('course_platformid','neq','')
                    ->order('course_hotsort desc,course_id desc')
                    ->limit(4)
                    ->select();
        if($info)
        {
            $this->outData['data'] = $info;
            $this->outData['code'] = 1;
            $this->outData['message'] = "操作成功";
            return $this->outData;
        }else{
            $this->outData['code'] = 3;
            $this->outData['message'] = "暂无数据";
            return $this->outData;
        } 
   }

   //热门课程换一换
   public function changeHotCourse()
   {
        $info = Db::name('business_college_course')
                    ->field('course_id')
                    ->where('course_isdel','1')
                    ->where('course_ishot','1')
                    ->where('course_platformid','neq','')
                    ->select();
        if(count($info) < 4){
            $this->outData['code'] = 2;
            $this->outData['message'] = "热门课程数不足4个";
            return $this->outData;
        }
        $courseArr = array();
        foreach($info as $v){
            $courseArr[] = $v['course_id'];
        }
        $array_keys = array_rand($courseArr,4);
        $array_value = array();
        //获取热门id
        foreach($array_keys as $vo){
            $array_value[] = $courseArr[$vo];
        }
        $data = Db::name('business_college_course')
                    ->field('course_id,course_cover,course_title')
                    ->where('course_id','in',$array_value)
                    ->select();
        $this->outData['data'] = $data;
        $this->outData['code'] = 1;
        $this->outData['message'] = "操作成功";
        return $this->outData;
   }

   //微专题
   public function special()
   {
        $info = Db::name('business_college_course')
                    ->alias('c')
                    ->join('ylt_business_college_teacher t','t.tea_id = c.course_teaid')
                    ->field('c.course_id,c.course_cover,c.course_title,c.course_time,c.course_liul,t.tea_name')
                    ->where('course_isdel','1')
                    ->where('course_platformid','neq','')
                    ->where('course_isspecial','1')
                    ->order('course_specialsort desc,course_id desc')
                    ->limit(3)
                    ->select();
        if($info)
        {
            $this->outData['data'] = $info;
            $this->outData['code'] = 1;
            $this->outData['message'] = "操作成功";
            return $this->outData;
        }else{
            $this->outData['code'] = 3;
            $this->outData['message'] = "暂无数据";
            return $this->outData;
        }
   }

   //微专题更多 参数 当前页 page  每页显示条数  listRows
   public function specialMore()
   {
        $page = input('page');
        $listRows = input('listRows');
        $info = Db::name('business_college_course')
                    ->alias('c')
                    ->join('ylt_business_college_teacher t','t.tea_id = c.course_teaid')
                    ->field('c.course_id,c.course_cover,c.course_title,c.course_time,c.course_liul,t.tea_name')
                    ->where('course_isdel','1')
                    ->where('course_platformid','neq','')
                    ->where('course_isspecial','1')
                    ->order('course_specialsort desc,course_id desc')
                    ->page($page,$listRows)
                    ->select();
        if($info)
        {
            $this->outData['data'] = $info;
            $this->outData['code'] = 1;
            $this->outData['message'] = "操作成功";
            return $this->outData;
        }else{
            $this->outData['code'] = 3;
            $this->outData['message'] = "暂无数据";
            return $this->outData;
        }
   }

   //微专题分类 参数 course_type 直播 藏宝 消息 开店 增溢  当前页 page  每页显示条数  listRows
   public function specialLive()
   {
        $page = input('page');
        $listRows = input('listRows');
        $type = input('course_type');
        $info = Db::name('business_college_course')
                    ->alias('c')
                    ->join('ylt_business_college_teacher t','t.tea_id = c.course_teaid')
                    ->field('c.course_id,c.course_cover,c.course_title,c.course_time,c.course_liul,t.tea_name')
                    ->where('course_isdel','1')
                    ->where('course_platformid','neq','')
                    ->where('course_isspecial','1')
                    ->where('course_type',$type)
                    ->order('course_specialsort desc,course_id desc')
                    ->page($page,$listRows)
                    ->select();
        if($info)
        {
            $this->outData['data'] = $info;
            $this->outData['code'] = 1;
            $this->outData['message'] = "操作成功";
            return $this->outData;
        }else{
            $this->outData['code'] = 3;
            $this->outData['message'] = "暂无数据";
            return $this->outData;
        }
   }

   //名师云集
   public function recommendTeacher()
   {
        $info = Db::name('business_college_teacher')
                    ->field('tea_id,tea_pic,tea_post,tea_name')
                    ->where('tea_isdel','1')
                    ->where('tea_platformid','neq','')
                    ->order('tea_sort desc,tea_id desc')
                    ->limit(3)
                    ->select();
        if($info)
        {
            $this->outData['data'] = $info;
            $this->outData['code'] = 1;
            $this->outData['message'] = "操作成功";
            return $this->outData;
        }else{
            $this->outData['code'] = 3;
            $this->outData['message'] = "暂无数据";
            return $this->outData;
        }
   }
   //讲师列表  参数 搜索内容  keyword  当前页 page  每页显示条数  listRows
   public function teacherList()
   {
        $page = input('page');
        $listRows = input('listRows');
        // 是否有参数传入
        if (input('?param.keyword')) {
            $keyword = input('param.keyword');
        } else {
            $keyword = '';
        }
        $info = Db::name('business_college_teacher')
                    ->field('tea_id,tea_pic,tea_post,tea_name,tea_des')
                    ->where('tea_isdel','1')
                    ->where('tea_platformid','neq','')
                    ->where('tea_name|tea_des','like','%'.$keyword.'%')
                    ->order('tea_sort desc,tea_id desc')
                    ->page($page,$listRows)
                    ->select();
        if($info)
        {
            $this->outData['data'] = $info;
            $this->outData['code'] = 1;
            $this->outData['message'] = "操作成功";
            return $this->outData;
        }else{
            $this->outData['code'] = 3;
            $this->outData['message'] = "暂无数据";
            return $this->outData;
        }
   }

   //讲师详情 参数讲师tea_id
   public function teacherDetail()
   {
        $id = input('tea_id');
        $info['info']     = Db::name('business_college_teacher')
                            ->field('tea_pic,tea_name,tea_post,tea_des')
                            ->where('tea_id',$id)
                            ->find();
        $info['course']   = Db::name('business_college_course')
                            ->field('course_id,course_cover,course_title')
                            ->where('course_isdel','1')
                            ->where('course_platformid','neq','')
                            ->where('course_teaid',$id)
                            ->limit(4)
                            ->select();
        $info['material'] = Db::name('business_college_material')
                            ->field('mat_id,mat_cover,mat_title,mat_des')
                            ->where('mat_isdel','1')
                            ->where('mat_platformid','neq','')
                            ->where('mat_teaid',$id)
                            ->limit(3)
                            ->select();
        $this->outData['data'] = $info;
        $this->outData['code'] = 1;
        $this->outData['message'] = "操作成功";
        return $this->outData;
   }

   //讲师课程更多 讲师id tea_id
   public function teacherCourse()
   {
        $id = input('tea_id');
        $page = input('page');
        $listRows = input('listRows');
        $info = Db::name('business_college_course')
                    ->field('course_id,course_cover,course_title')
                    ->where('course_isdel','1')
                    ->where('course_platformid','neq','')
                    ->where('course_teaid',$id)
                    ->page($page,$listRows)
                    ->select();
        if($info)
        {
            $this->outData['data'] = $info;
            $this->outData['code'] = 1;
            $this->outData['message'] = "操作成功";
            return $this->outData;
        }else{
            $this->outData['code'] = 3;
            $this->outData['message'] = "暂无数据";
            return $this->outData;
        }
   }

  //讲师素材更多 讲师id tea_id
  public function teacherMaterial()
  {
      $id = input('tea_id');
      $page = input('page');
      $listRows = input('listRows');
      $info = Db::name('business_college_material')
                  ->field('mat_id,mat_cover,mat_title,mat_des')
                  ->where('mat_isdel','1')
                  ->where('mat_platformid','neq','')
                  ->where('mat_teaid',$id)
                  ->page($page,$listRows)
                  ->select();
      if($info)
        {
            $this->outData['data'] = $info;
            $this->outData['code'] = 1;
            $this->outData['message'] = "操作成功";
            return $this->outData;
        }else{
            $this->outData['code'] = 3;
            $this->outData['message'] = "暂无数据";
            return $this->outData;
        }
  }

  //商学院banner
  public function businessBanner()
  {
      $info = Db::name('business_college_banner')
                  ->field('ba_pic')
                  ->where('ba_isdel',1)
                  ->where('ba_platformid','neq','')
                  ->select();
      if($info)
        {
            $pic_arr = array();
            foreach($info as $v){
                $pic_arr[] = $v['ba_pic'];
            }
            $this->outData['data'] = $pic_arr;
            $this->outData['code'] = 1;
            $this->outData['message'] = "操作成功";
            return $this->outData;
        }else{
            $this->outData['code'] = 3;
            $this->outData['message'] = "暂无数据";
            return $this->outData;
        }
  }

  //讲师banner
  public function tbanner()
  {
      $info = Db::name('business_tbanner')
                  ->field('tb_pic')
                  ->where('tb_isdel',1)
                  ->where('tb_platformid','neq','')
                  ->select();
      if($info)
        {
            $pic_arr = array();
            foreach($info as $v){
                $pic_arr[] = $v['tb_pic'];
            }
            $this->outData['data'] = $pic_arr;
            $this->outData['code'] = 1;
            $this->outData['message'] = "操作成功";
            return $this->outData;
        }else{
            $this->outData['code'] = 3;
            $this->outData['message'] = "暂无数据";
            return $this->outData;
        }
  }





}